package com.seven.first.suite.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName SevenStringUtils
 * @Description TODO
 * @Author seven
 * @Date 2022/5/1616:24
 * @Version 1.0
 **/
public class SevenStringUtils {

    private final static Pattern p = Pattern.compile("[A-Z]");



    public static String upperCharToUnderLine(String param) {
        if (param == null || param.equals("")) {
            return "";
        }
        StringBuilder builder = new StringBuilder(param);
        Matcher mc = p.matcher(param);
        int i = 0;
        while (mc.find()) {
            builder.replace(mc.start() + i, mc.end() + i, "_" + mc.group().toLowerCase());
            i++;
        }

        if ('_' == builder.charAt(0)) {
            builder.deleteCharAt(0);
        }
        return builder.toString();
    }




}
